using System.Collections.Generic;
using UnityEngine;

public class ParticleCollision : MonoBehaviour
{
    ParticleSystem particle;  // 粒子系统对象
    public GameObject splatPrefab;  // 飞溅预制体
    private List<ParticleCollisionEvent> collisionEvents = new List<ParticleCollisionEvent>();  // 碰撞事件列表

    private void Start()
    {
        particle = GetComponent<ParticleSystem>();  // 获取粒子系统组件
    }

    private void OnParticleCollision(GameObject other)
    {
        ParticlePhysicsExtensions.GetCollisionEvents(particle, other, collisionEvents);  // 获取碰撞事件

        int count = collisionEvents.Count;  // 碰撞事件数量
        for (int i = 0; i < count; i++)
        {
            // 在碰撞点实例化飞溅预制体
            // Instantiate(splatPrefab, collisionEvents[i].intersection, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)), splatHolder);
            GameObject go = ObjectPool.GetObject(splatPrefab);
            go.transform.localPosition = collisionEvents[i].intersection;
        }
    }
}
